#include <jni.h>
#include <string>
#include "plog.h"
#include "invoke_java.h"

extern "C" JNIEXPORT jstring JNICALL
Java_com_frezrik_jnidemo_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

inline static void load_dex(JNIEnv *env, jobject base) {

    int sdk_int = GetStaticField("android/os/Build$VERSION", "SDK_INT", "I").i;
    LOGD("sdk_int %d\n", sdk_int);

    jobject dexDir = CallObjectMethod(base, "getDir", "(Ljava/lang/String;I)Ljava/io/File;", "dex", 0).l;
    //CallObjectMethod(dexDir, "mkdir", "()Z");
    /*jstring path = static_cast<jstring>(CallObjectMethod(dexDir, "getPath",
                                                         "()Ljava/lang/String;").l);

    LOGD("%s", path);*/

}











extern "C" JNIEXPORT void JNICALL
Java_com_frezrik_jnidemo_MainActivity_attach(
        JNIEnv* env,
        jclass jclass, jobject base) {
    LOGD("attach");

    SetEnv(env, base);

    load_dex(env, base);
}